﻿using Castle.Facilities.NHibernateIntegration;
using Castle.Facilities.NHibernateIntegration.SessionStores;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Inovout.Repositories
{
    public class ManagedWebSessionStore : CallContextSessionStore
    {
        //因为多线程无法共享HttpContext，加之ISession是线程不安全，故在WEB应用，采用按线程
        public IEnumerable<SessionDelegate> FindAllCompatibleSession()
        {
            List<SessionDelegate> sessions = new List<SessionDelegate>();
            IDictionary alias2Stack = GetDictionary();
            if (alias2Stack != null)
            {
                foreach (var stackDictionary in alias2Stack)
                {
                    Stack stack = ((DictionaryEntry)stackDictionary).Value as Stack;
                    sessions.AddRange(stack.ToArray().Cast<SessionDelegate>());
                }
            }
            return sessions;
        }
    }
}
